﻿CREATE PROCEDURE [dbo].[Text_BookTree_ChangePublishStatus]
	@url NVARCHAR(450)
AS
BEGIN
	SET @url = LTRIM(RTRIM(LOWER(@url)))

	UPDATE t
	SET [Published] = CASE WHEN [Published] = 1 THEN 0 ELSE 1 END
			, [PublishedDate] = CASE WHEN [Published] = 1 THEN NULL ELSE GETUTCDATE() END
	FROM [dbo].[text_BookTree] AS t
	INNER JOIN [dbo].[text_BookTree_Cache] AS c ON t.[BookTreeId] = c.[BookTreeId]
	WHERE c.[Url] = @url

END